package com.windfone.web.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.windfone.model.Pricehistory;
import com.windfone.model.Product;
import com.windfone.model.ProductType;
import com.windfone.service.CommonService;
import com.windfone.service.ProductService;
import com.windfone.service.ProductTypeService;

public class PriceHistoryAdminAction extends ActionSupport {
	private CommonService commonService;
	private ProductTypeService productTypeService;
	private ProductService productService;
	private List<Product> productList;
	private List<Pricehistory> pricehistorys;
	private int priceHisId;
	public int getPriceHisId() {
		return priceHisId;
	}
	public void setPriceHisId(int priceHisId) {
		this.priceHisId = priceHisId;
	}
	public List<Product> getProductList() {
		return productList;
	}
	public List<ProductType> getProductTypeList() {
		return productTypeList;
	}
	public void setProductList(List<Product> productList) {
		this.productList = productList;
	}
	public void setProductTypeList(List<ProductType> productTypeList) {
		this.productTypeList = productTypeList;
	}
	private List<ProductType> productTypeList;
	public void setCommonService(CommonService commonService) {
		this.commonService = commonService;
	}
	public void setProductTypeService(ProductTypeService productTypeService) {
		this.productTypeService = productTypeService;
	}
	@Override
	public String execute() throws Exception {
		return super.execute();
	}
	public String priceHisList() throws Exception {
		productTypeList = productTypeService.listProductType();
		
		return SUCCESS;
	}
	public String priceHisQry() throws Exception {
		productTypeList = productTypeService.listProductType();
		String wherecondition = "";
		if ( productyTypeIdQ !=-1){
			wherecondition = wherecondition + " AND p.producttypeId="+productyTypeIdQ;
		}
		if ( beginDate!=null && !beginDate.equals("") ){
			wherecondition = wherecondition + "  AND h.createTime>='"+beginDate +"' ";
		}
		if ( endDate!=null && !endDate.equals("") ){
			wherecondition = wherecondition + "  AND h.createTime<='"+ endDate  +"'  ";
		}
		pricehistorys = commonService.qryPriceHistory(wherecondition);
		return SUCCESS;
	}
	public List<Pricehistory> getPricehistorys() {
		return pricehistorys;
	}
	public void setPricehistorys(List<Pricehistory> pricehistorys) {
		this.pricehistorys = pricehistorys;
	}
	public int getProductyTypeIdQ() {
		return productyTypeIdQ;
	}
	public String getBeginDate() {
		return beginDate;
	}
	public void setProductService(ProductService productService) {
		this.productService = productService;
	}
	public String getEndDate() {
		return endDate;
	}
	public void setProductyTypeIdQ(int productyTypeIdQ) {
		this.productyTypeIdQ = productyTypeIdQ;
	}
	public void setBeginDate(String beginDate) {
		this.beginDate = beginDate;
	}
	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}
	private int productyTypeIdQ = -1;
	private String beginDate;
	private String endDate;
	public String delPriceHis() throws Exception {
		int i = commonService.delPriceByKey( priceHisId );
		return SUCCESS;
	}
	public String addPriceQry() throws Exception {
		String whereCondition = "  p.productTypeId=t.id ";
		if ( productyTypeIdQ !=-1 ){
			whereCondition = whereCondition + " AND productTypeId="+ productyTypeIdQ;
		}
		if ( beginDate!=null && !beginDate.equals("") ){
			whereCondition = whereCondition + "  AND p.createTime>='"+beginDate +"' ";
		}
		if ( endDate!=null && !endDate.equals("") ){
			whereCondition = whereCondition + "  AND p.createTime<='"+ endDate  +"'  ";
		}
//		PageUtil pu = new PageUtil();
//		pu.setCurrentPage(currentPage);
//		int totalRecords = productService.getAllRecorderNumber(whereCondition) ;
//		pu.setTotalRecords( totalRecords );
//		pu.setPageSize(Constant.PAGE_SIZE);
//		pu.dealPage();
//		currentPage = pu.getCurrentPage();
//		nextPage = pu.getNextPage();
//		totalPage = pu.getTotalPage();
//		prevPage = pu.getPrevPage();
//		
//		beginRecord = Constant.PAGE_SIZE * (currentPage -1);
//		if ( beginRecord< 0 )
//			beginRecord = 0; 
//		productList = productService.getAllProduct(beginRecord,whereCondition);
		productList = productService.getAllProductByWherecondition(whereCondition);
		return SUCCESS;
	}

}
